<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>

    <script>
      /* 
            解构赋值
        */

      const arr = ['GG', 'XX', 'XXX'];
      let a,
        b,
        c;

        /* 
            a = arr[0]
            b = arr[1]
            c = arr[2]
        */
      [a, b, c] = arr;
      console.log(a, b, c);
      let [d, e, f, g] = ['DD', 'XXSFDAF', 'DSDSAD',"sdadas"]; //声明的同时结构

      console.log(d, e, f, g);
      [d, e, f = 77, g = g] = [1,3,2];
      console.log(d,e,f,g);
      let [n1,n2,...n3] = [1,2,3,4,5] //解构数组时,可以使用...来设置获取更多的剩余元素
      console.log(n1,n2,n3);

    //   通过函数结构赋值
    function fn(){
        return ["DDDD","Dsadas"]
    }
    let [g1,g2] = fn()
    console.log(g1,g2);
    // 通过结构数值,迅速交换赋值
    let w1 = 10,w2 = 20
    ;[w1,w2] = [w2,w1] //左边的是变量,右边的是数值!
    console.log(w1,w2);

    /* 
    数值中可以存储任意数据类型,也可以存数组,
        如果一个数组中的元素还是数组,我们称之为二维数组
    */
   const arr1  = [[1,2,3],[7,5,6]]
   let [[y,u,i],[h,j,k]] = arr1
   console.log(y,u,i,h,j,k);
   [[y,u,i],[h,j,k]]  = [[h,j,k],[y,u,i]] 
   console.log(y,u,i,h,j,k);


    // 遍历数组
   for (const i of arr1) {
        for (const v of i ) {
            console.log(v);
        }
   }

    </script>
  </head>
  <body></body>
</html>
